<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<isperp:incidentView>
	<jsp:body> 
 <jsp:include page="step1view.jsp"></jsp:include> 
 
 <script type="text/javascript">
	function resetPriorityName() {
		var $urgencyName = $("#urgencyName option:selected"), urgencyNameCode = parseInt($urgencyName.data("code"));
		var $effectName = $("#effectName option:selected"), effectNameCode = parseInt($effectName.data("code"));

		var ueVal = urgencyNameCode + effectNameCode;

		var $priorityName = $("#priorityName"), $priorityNameOptions = $("#priorityName option");

		for ( var i = 0; i < $priorityNameOptions.length; i++) {
			var $item = $($priorityNameOptions[i]), code = parseInt($item.data("code"));

			if (ueVal >= code) {
				$priorityName.val($item.val());
				$("#priorityName").trigger("chosen:updated");
				return;
			}
		}

	}

	$("#slmId").chosen({
		width : "155px"
	}).change(function() {
		getSlmTarget()
	});
	function getSlm(projectId, businessKey) {
		$.getJSON("slm/serviceAgreement/getSlm", {
			projectId : "${model.projectId}",
			processKey : "incidentProcess",
			businessKey : "${model.id}"
		}, function(data) {
			$("#slmId").empty();
			if (data) {
				$(data).each(function(index, item) {
					$("#slmId").append('<option value="'+item.id+'">' + item.name + '</option>');
				});

			}
			$("#slmId").trigger("chosen:updated");
			getSlmTarget();
		});
	}

	function getSlmTarget() {
		$("#slmName").val($("#slmId option:selected").text());
		$("#slmDetalLabel").empty();

		$.getJSON("slm/serviceAgreement/getSlmTarget", {
			grgumentId : $("#slmId").val()
		}, function(data) {
			var s = "";
			if (data) {
				$(data).each(function(index, item) {
					s += item.name + "：" + item.target + ";"

				});

			}
			$("#slmDetalLabel").html(s);
		});

	}

	function getAddressByLoactionDiv(cellValue, rowObject) {
		if (rowObject.longitude && rowObject.latitude && rowObject.longitude != "" && rowObject.latitude != "") {
			var location = (rowObject.latitude + "") + "," + (rowObject.longitude + "");
			return "<div class='location_div' style='white-space:pre-wrap' id='row_"+rowObject.id+"' data-id='"+rowObject.id+"' data-location='"+location+"'>加载中...</div>";
		}

		return "";
	}
	function getAddressByLoaction() {

		var address = "";

		$(".location_div").each(function(index, item) {
			var $item = $(item);
			var location = $item.data("location"), id = $item.data("id");

			$.ajax({
				type : "get",
				dataType : "jsonp",
				async : false,
				url : "http://api.map.baidu.com/geocoder/v2/?ak=" + isperp.baiduApk + "&callback=renderReverse&location=" + location + "&output=json&pois=0",
				success : function(data) {
					$("#row_" + id).html(data.result.formatted_address);
				}

			})

		});

	}
</script>
<script type="text/javascript">
	function projectMemberGrid_OndbClick(rowid) {
		var rowD = projectMemberGrid.getRowData(rowid);

		$("#supporterId").val(rowD.name);

		$("#supporterName").val(rowD.fullname);
	}

	function projectMemberGrid_ActionFormatter(cellvalue, rowObject) {
		return "<a href='javascript:void(0);' onclick='projectMemberGrid_OndbClick(\"" + rowObject.id + "\")'>[选择]</a>";
	}

	function project_Onchange() {

		$("#supporterId,#supporterName").val("");
		projectMemberGrid.reload();
	}
	function printIncident(id) {
		var tempTitle = "打印事件单";
		var tempUrl = "ReportServer?reportlet=incident/cpt_incident_print.cpt&op=write&incident_id=" + id;
		var options = {
			title : tempTitle,
			contentUrl : tempUrl
		};
		isperp.openDialog(options);
	}
</script>
 
<form:form id="formIncidentAssign" commandName="model"
	cssClass="validate" action="incident/incident/save">
	
	<div class="box no-border">
		<div class="header">
			<h3>事件信息</h3>
		</div>

		<table class="form-table">

			<tr>
				<td class="td1">事件标题：</td>
				<td class="td2" colspan="3"><input id="incidentTitle"
					name="title" value="${model.title }" class="required" type="text"
					maxlength="200" style="width:80%">
				</td>
			</tr>
			<tr>
				<td class="td1">事件描述：</td>
				<td class="td2" colspan="3"><textarea id="incidentDescription"
						class="required" name="description">${model.description }</textarea>
				</td>
			</tr>
			<tr>
				<td class="td1">发生频率：</td>
				<td class="td2"><isperp:dictSelector
						typeCode="OCCURRENCE_FREQUENCY" id="occurrenceFrequency"
						name="occurrenceFrequency" hasEmptyValue="false"
						selectedValue="${model.occurrenceFrequency }"></isperp:dictSelector>
				</td>
				<td class="td1">期望完成日期：</td>
				<td class="td2"><input name="expectTime"
					value="${model.expectTime }" type="datetime" class="datetime">
				</td>
			</tr>
			<tr>

				<td class="td1">来源：</td>
				<td class="td2" colspan="3"><isperp:dictSelector
						typeCode="INCIDENT_SOURCE" name="source" id="source"
						hasEmptyValue="false" dictCssClass="required"
						selectedValue="${model.source }"></isperp:dictSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">项目：</td>
				<td class="td2" colspan="3"><form:select path="projectId"
						cssClass="required" items="${projects}" itemValue="id"
						itemLabel="name" onchange="project_Onchange()" />
				</td>
			</tr>
			<tr id="assetTr">


				<td class="td1">服务目录：</td>
				<td class="td2" colspan="3"><input id="serviceCategoryId"
					name="serviceCategoryId" type="hidden"
					value="${model.serviceCategoryId }"> <isperp:listSelector
						id="serviceCategoryIdSelector" displayValueCssClass="required"
						showClearBtn="false"
						urlExtScript="'?projectId='+$('#projectId').val()"
						url="project/service/listDetail" inputReadonly="true"
						displayColumn="name"
						displayValue="${relationIncident.service_category_name}"
						valueColumn="id" valueControlId="serviceCategoryId">
						<isperp:grid gridId="serviceCategoryGrid" showPager="false" url=""
							showSearchbar="false" showToolbar="false"
							cusFormatterActions="false" autoload="false">
							<isperp:column name="id" title="id" hidden="true"></isperp:column>
							<isperp:column name="code" title="编号" width="70">
							</isperp:column>
							<isperp:column name="name" title="名称" width="80"></isperp:column>
							<isperp:column name="category_name" title="分类" width="80">
							</isperp:column>
							<isperp:column name="keyword" title="关键字" width="150">
							</isperp:column>
						</isperp:grid>
					</isperp:listSelector></td>
			</tr>
			<tr id="assetTr">
				<td class="td1">关联资产：</td>
				<td class="td2" colspan="3"><isperp:ciUseRelation relationId="${model.id }"
						viewOnly="false" relationType="incidentProcess"></isperp:ciUseRelation>
				</td>
			</tr>
			<tr>
				<td class="td1">附件：</td>
				<td class="td2" colspan="3"><isperp:uploader
						sourceId="${model.id }" id="incidentFiles"></isperp:uploader>
				</td>
			</tr>


			<tr>
				<td colspan="4">
					<div class="header">
						<h3>分类信息</h3>
					</div></td>
			</tr>

			<tr>
				<td class="td1">事件分类：</td>
				<td class="td2"><form:hidden path="id" /> <form:hidden
						path="icdCategoryId" /> <isperp:treeSelector
						url="incident/category/getTree" id="icdCategorySelector"
						name="icdCategoryName" displayValue="${model.icdCategoryName }"
						valueControlId="icdCategoryId" displayValueCssClass="required"></isperp:treeSelector>
				</td>
			</tr>
			<tr>

				<td class="td1">紧急度：</td>
				<td class="td2" colspan="3"><isperp:dictSelector
						typeCode="INCIDENT_URGENCY" name="urgencyName" id="urgencyName"
						hasEmptyValue="false" dictCssClass="required"
						onchangeFunc="resetPriorityName()"
						selectedValue="${model.urgencyName }"></isperp:dictSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">影响度：</td>
				<td class="td2"><isperp:dictSelector typeCode="INCIDENT_EFFECT"
						name="effectName" id="effectName" hasEmptyValue="false"
						dictCssClass="required" onchangeFunc="resetPriorityName()"
						selectedValue="${model.effectName }"></isperp:dictSelector></td>

				<td class="td1">优先级：</td>
				<td class="td2"><isperp:dictSelector
						typeCode="INCIDENT_PRIORITY" name="priorityName" id="priorityName"
						hasEmptyValue="false" dictCssClass="required"
						selectedValue="${model.priorityName }"></isperp:dictSelector>
				</td>
			</tr>
			
			 <tr id="supporter_tr2line">
		        <td class="td1">支持人员：</td>
		       <td class="td2" ><form:hidden path="supporterId" /> <isperp:departmentUser
				displayValue="${model.supporterName}" ifIncludeNoRoleUser="false"
				multiselect="false"
				displayValueCssClass="required" idFieldName="name"
				valueControlId="supporterId" id="supporterName" name="supporterName"
				></isperp:departmentUser></td>
	        </tr> 

			<%-- <tr>
				<td class="td1">支持人员：</td>
				<td class="td2" colspan="3"><form:hidden path="supporterId" />
					<form:input path="supporterName" cssClass="required"
						readonly="true" /></td>
			</tr> --%>
		</table>


	</div>
</form:form>
<%-- <isperp:grid url="project/member/projectMemberUserList"
	postData="projectId:function() { return $('#projectId').val();}"
	showPager="false" showSearchbar="false" gridId="projectMemberGrid"
	height="auto" gridTitle="${pageTitle}" cusFormatterActions="false"
	ondbClickRowEvent="projectMemberGrid_OndbClick(rowid);"
	loadComplete="getAddressByLoaction()">
	<isperp:column name="id" title="id" hidden="true"></isperp:column>
	<isperp:column name="fullname" title="姓名" width="80">
	</isperp:column>
	<isperp:column name="position_name" title="职位" width="100">
	</isperp:column>
	<isperp:column name="mobile" title="电话" width="90">
	</isperp:column>
	<isperp:column name="process_count" title="任务数" width="60">
	</isperp:column>

	<isperp:column name="longitude" title="longitude" hidden="true">
	</isperp:column>
	<isperp:column name="latitude" title="latitude" hidden="true">
	</isperp:column>

	<isperp:column name="actInDate" title="当前位置" width="180"
		isFormatterFun="true"
		formatter="return getAddressByLoactionDiv(cellvalue,rowObject);">
	</isperp:column>
	<isperp:column name="skills" title="技能水平" width="100">
	</isperp:column>
	<isperp:column name="name" title="name" hidden="true">
	</isperp:column>
	<isperp:column name="" title="操作" isFormatterFun="true"
		formatter="return projectMemberGrid_ActionFormatter(cellvalue,rowObject);"
		align="center" width="60">
	</isperp:column>
</isperp:grid> --%>

	</jsp:body>
</isperp:incidentView>


<isperp:buttonList>

	<isperp:processButtons processKey="incidentProcess"
		processId="${model.processId }" businessKey="${model.id }"
		formId="formIncidentAssign"></isperp:processButtons>
	<button onclick="printIncident('${model.id}')">
		<span class="icon icon-ok"></span>打印事件单
	</button>
</isperp:buttonList>
